
cd "C:\Users\sertsios\Dropbox\LPSU replication package RFS\Replication\Log files\Appendix Tables"
clear
log using TableA6.txt, text replace 

**Panel to cross-sectional comparison

****Part I-Start with panel regressions
clear
cd "C:\Users\sertsios\Dropbox\LPSU replication package RFS\Data"
use LPSU_MainSample_Sep2024, replace

cd "C:\Users\sertsios\Dropbox\LPSU replication package RFS\Tables"

***Set of fixed effects
egen sic1year=group(sic1 year)
qui tabulate sic1year, generate(dsic1year)
egen month_post= group(month post)
qui tabulate month_post, generate(dmonth)
qui tabulate year_around_ipo, generate(deventyear) 

eststo clear  


set more off
eststo:qui xtivreg2 wroa (IPO=instrument) deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth* , fe first cluster(id) partial(deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth*)
gen sample_IV=e(sample) 
keep if sample_IV==1
outreg2 using Table_Panel_to_CS, keep(IPO) sortvar(IPO)  tex(frag) word bdec(3) nocons nor2 label ///
 addtext(Data structure, Panel, Firm FE, Yes, Event year FE, Yes, SIC x calendar year FE, Yes,  IPO month x Post FE, Yes, ///
 Filling year x Post FE, No, Country x Post FE, No, SIC FE, No, Month FE, No, Filling year FE, No, Country FE, No, Sample, Baseline)  replace
esttab,   keep(IPO) order(IPO) label se b(%9.3f) se(%9.3f) nor2 star(* 0.1 ** 0.05 *** 0.01) ///
 addnotes(Data structure, Panel, Firm FE, Yes, Event year FE, Yes, SIC x calendar year FE, Yes,  IPO month x Post FE, Yes, ///
 Filling year x Post FE, No, Country x Post FE, No, SIC FE, No, Month FE, No, Filling year FE, No, Country FE, No, Sample, Baseline) 
eststo clear 
 
 
**To make a fair comparison with the Cross-sectional regression, we need to satisfy wo additional criteria:
 
**1-Keep only  firms with ROA before and after
bysort id: egen max_post=max(post)
bysort id: egen min_post=min(post)
distinct id if max_post==1 & min_post==0
gen roa_pre_post=0
replace roa_pre_post=1 if max_post==1 & min_post==0

**Replicate result restricting the sample to firms with roa before and after
 set more off
eststo:qui xtivreg2 wroa (IPO=instrument) deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth* if roa_pre_post==1, fe first cluster(id) partial(deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth*)
outreg2 using Table_Panel_to_CS, keep(IPO) sortvar(IPO)  tex(frag) word bdec(3) nocons nor2 label ///
 addtext(Data structure, Panel, Firm FE, Yes, Event year FE, Yes, SIC x calendar year FE, Yes,  IPO month x Post FE, Yes, ///
 Filling year x Post FE, No, Country x Post FE, No, SIC FE, No,  Month FE, No, Filling year FE, No, Country FE, No, Sample, OROA pre-post)  
esttab,   keep(IPO) order(IPO) label se b(%9.3f) se(%9.3f) nor2 star(* 0.1 ** 0.05 *** 0.01) ///
 addnotes(Data structure, Panel, Firm FE, Yes, Event year FE, Yes, SIC x calendar year FE, Yes,  IPO month x Post FE, Yes, ///
 Filling year x Post FE, No, Country x Post FE, No, SIC FE, No,  Month FE, No, Filling year FE, No, Country FE, No, Sample, OROA pre-post) 
eststo clear  
 
**2-Defining additional FEs for a fair comparison with the cross-sectional estimaton.
** filing year-post FEs
egen fil_post= group(filing_yr post)
qui tabulate fil_post, generate(dfil_post)
**Defining country-post FE
egen country_post=group(countryname post)
qui tabulate country_post, generate(dcountry_p)

 set more off
eststo:qui xtivreg2 wroa (IPO=instrument) deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth* dfil_post* dcountry_p* if roa_pre_post==1, fe first cluster(id) ///
 partial(deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth* dfil_post* dcountry_p*)
outreg2 using Table_Panel_to_CS, keep(IPO) sortvar(IPO)  tex(frag) word bdec(3) nocons nor2 label ///
 addtext(Data structure, Panel, Firm FE, Yes, Event year FE, Yes, SIC x calendar year FE, Yes,  IPO month x Post FE, Yes, ///
 Filling year x Post FE, Yes, Country x Post FE, Yes, SIC FE, No, Month FE, No, Filling year FE, No, Country FE, No, Sample, OROA pre-post)  
esttab,   keep(IPO) order(IPO) label se b(%9.3f) se(%9.3f) nor2 star(* 0.1 ** 0.05 *** 0.01) ///
 addnotes(Data structure, Panel, Firm FE, Yes, Event year FE, Yes, SIC x calendar year FE, Yes,  IPO month x Post FE, Yes, ///
 Filling year x Post FE, Yes, Country x Post FE, Yes, SIC FE, No, Month FE, No, Filling year FE, No, Country FE, No, Sample, OROA pre-post) 
eststo clear 
 
 

**Part II: Convert panel into a cross-section 
**We will keep pre vs post-attempt averages and then collapsed the pre-post panel into a cross-sectopm 
 
***Start from panel sample. 
clear
cd "C:\Users\sertsios\Dropbox\LPSU replication package RFS\Data"
use LPSU_MainSample_Sep2024, replace

cd "C:\Users\sertsios\Dropbox\LPSU replication package RFS\Tables"
label var ipo "IPO"

**Getting averages over the pre & post periods periods
foreach i of varlist wroa assets_MM num_subs_w num_countries_w wleverage sales_MM {
bysort id post: egen mean_`i'=mean(`i')
}

*
**Keeping relevant variables
drop if post==.
keep mean* id post filing_y lag30 sic1 sic2 ipo month pos_returns cntr_cde
duplicates drop
bysort id : egen count_obs=count(post)
tab count_obs
**We have two periods for each firm-attempt: Before and after

order mean* id post count_obs filing_y lag30 sic1 sic2 ipo month pos_returns cntr_cde

**Reshaping the panel
reshape wide mean_wroa mean_assets_MM mean_num_subs_w mean_num_countries_w mean_wleverage mean_sales_MM, i(id) j(post)
gen delta_roa=mean_wroa1 - mean_wroa0
label var delta_roa "Delta ROA"
**Variables ending in "1" ("0") are post (pre) attempt

**Defining controls:
gen log_assets_pre=log(1+mean_assets_MM0)
gen log_subs_pre=log(1+mean_num_subs_w0)
gen log_countries_pre=log(1+mean_num_countries_w0)
gen log_sals_pre=log(1+mean_sales_MM0)

***Defining FEs
qui tabulate sic1, generate(d1sic)
qui tabulate filing_yr, generate(dyear)
qui tabulate month, generate(d_month)
egen country=group(cntr_cde)
qui tabulate cntr_cde, generate(dcountry)
egen sic1_filyear=group(sic1 filing_yr)
qui tabulate sic1_filyear, generate(dsic1_filyear)


**Baseline cross-sectional specification 
eststo:qui ivreg2 delta_roa  (ipo =pos_returns), cl(id) 
outreg2 using Table_Panel_to_CS, keep(ipo) sortvar(IPO ipo)  tex(frag) word bdec(3) nocons nor2 label ///
 addtext(Data structure, Cross-section, Firm FE, No, Event year FE, No, SIC x calendar year FE,No,  IPO month x Post FE, No, ///
 Filling year x Post FE, No, Country x Post FE, No, SIC FE, No, Month FE, No, Filling year FE, No, Country FE, No, Sample, OROA pre-post)  
esttab,   keep(ipo) order(IPO) label se b(%9.3f) se(%9.3f) nor2 star(* 0.1 ** 0.05 *** 0.01) ///
 addnotes(Data structure, Cross-section, Firm FE, No, Event year FE, No, SIC x calendar year FE,No,  IPO month x Post FE, No, ///
 Filling year x Post FE, No, Country x Post FE, No, SIC FE, No, Month FE, No, Filling year FE, No, Country FE, No, Sample, OROA pre-post)  
eststo clear 
 
 
**Cross-sectional specification including several pre-attempt controls and FEs
eststo:qui ivreg2 delta_roa d1sic* dyear* d_month* dcountry* log_assets_pre log_subs_pre mean_wleverage0 (ipo =pos_returns), cl(id) partial(d1sic* dyear* d_month* dcountry*)
outreg2 using Table_Panel_to_CS, keep(ipo) sortvar(IPO ipo)  tex(frag) word bdec(3) nocons nor2 label ///
 addtext(Data structure, Cross-section, Firm FE, No, Event year FE, No, SIC x calendar year FE,No,  IPO month x Post FE, No, ///
 Filling year x Post FE, No, Country x Post FE, No, SIC FE, Yes, Month FE, Yes, Filling year FE, Yes, Country FE, Yes, Sample, OROA pre-post+controls)  
 esttab,   keep(ipo) order(IPO) label se b(%9.3f) se(%9.3f) nor2 star(* 0.1 ** 0.05 *** 0.01) ///
 addnotes(Data structure, Cross-section, Firm FE, No, Event year FE, No, SIC x calendar year FE,No,  IPO month x Post FE, No, ///
 Filling year x Post FE, No, Country x Post FE, No, SIC FE, Yes, Month FE, Yes, Filling year FE, Yes, Country FE, Yes, Sample, OROA pre-post+controls)    
eststo clear 


 
cd "C:\Users\sertsios\Dropbox\LPSU replication package RFS\Replication\Log files\Appendix Tables"
log close  

